package com.lyf.scm.plan.domain.service.impl;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.lyf.scm.common.constants.CommonConstants;
import com.lyf.scm.common.enums.*;
import com.lyf.scm.plan.api.dto.DirectlyStoreDTO;
import com.lyf.scm.plan.api.dto.DirectlyStoreQueryDTO;
import com.lyf.scm.plan.api.dto.UnitRateQueryDTO;
import com.lyf.scm.plan.domain.remote.basedata.dto.ChannelDTO;
import com.lyf.scm.plan.domain.remote.basedata.facade.BaseDataFacade;
import com.lyf.scm.plan.domain.remote.bigdata.dto.*;
import com.lyf.scm.plan.domain.remote.bigdata.facade.BlOlapFacade;
import com.lyf.scm.plan.domain.remote.item.dto.SkuUnitDTO;
import com.lyf.scm.plan.domain.remote.item.dto.TagSkuInfoDTO;
import com.lyf.scm.plan.domain.remote.item.facade.ItemCoreFacade;
import com.lyf.scm.plan.domain.remote.promotion.dto.SinglePromotionItemDTO;
import com.lyf.scm.plan.domain.remote.promotion.facade.PromotionCoreFacade;
import com.lyf.scm.plan.domain.remote.stock.dto.QueryRealTimeStockDTO;
import com.lyf.scm.plan.domain.remote.stock.dto.RealTimeStockDTO;
import com.lyf.scm.plan.domain.remote.stock.facade.StockCoreFacade;
import com.lyf.scm.plan.domain.repository.DirectlyStoreRepository;
import com.lyf.scm.plan.domain.repository.OperationLogRecordRepository;
import com.lyf.scm.plan.domain.service.DirectlyStoreService;
import com.lyf.scm.plan.domain.service.RedisCacheService;
import com.lyf.scm.plan.insfrastructure.db.dataobject.bigdata.DirectlyStoreInDO;
import com.lyf.scm.plan.insfrastructure.db.dataobject.bigdata.DirectlyStoreUpDO;
import com.rome.arch.core.exception.RomeException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

import static com.lyf.scm.common.util.BatchHandlerUtil.splitTo;
import static com.lyf.scm.plan.domain.util.BigDataCacheUtil.*;

/**
 * description:
 *
 * @author: 李兵兵
 * @data: 2020/8/29 17:11
 */
@Slf4j
@Service
public class DirectlyStoreServiceImpl implements DirectlyStoreService {

    @Resource
    private DirectlyStoreRepository directlyStoreRepository;
    @Resource
    private BlOlapFacade blOlapFacade;
    //test 临时用来判断是否有异常
//    @Resource
//    private RedisServiceImpl redisServiceImpl;
    //    @Resource
//    private DataSource dataSource;
    @Resource
    private StockCoreFacade stockCoreFacade;
    @Resource
    private BaseDataFacade baseDataFacade;
    @Resource
    private PromotionCoreFacade promotionCoreFacade;
    @Resource
    private ItemCoreFacade itemCoreFacade;
    @Resource
    private RedisCacheService redisCacheService;
    @Resource
    private OperationLogRecordRepository operationLogRecordRepository;

    @Override
    public List<DirectlyStoreDTO> listBySelective(DirectlyStoreQueryDTO directlyStoreQueryDTO) {
        //先从表中查询出对应的sku
        List<DirectlyStoreDTO> list = directlyStoreRepository.listBySelective(directlyStoreQueryDTO);
        List<DirectlyStoreDTO> storeDTOS = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(list)) {
            List<String> skuCodeList = this.dealTag(directlyStoreQueryDTO, list);
            if (CollectionUtils.isNotEmpty(skuCodeList)) {
                storeDTOS.addAll(list.stream().filter(item -> skuCodeList.contains(item.getSkuCode())).collect(Collectors.toList()));
                List<String> skuList = storeDTOS.stream().map(DirectlyStoreDTO::getSkuCode).distinct().collect(Collectors.toList());
                List<String> storeCodeList = storeDTOS.stream().map(DirectlyStoreDTO::getStoreCode).distinct().collect(Collectors.toList());
                //实际收货量
                StockInAndOutDTO stockInAndOutDTO = new StockInAndOutDTO();
                stockInAndOutDTO.setWarehouseCode(directlyStoreQueryDTO.getStoreCode());
                stockInAndOutDTO.setSkuCodeList(skuList);
                stockInAndOutDTO.setStartTime(DateUtil.format(directlyStoreQueryDTO.getFormulateDate(), DatePattern.NORM_DATE_PATTERN));
                stockInAndOutDTO.setEndTime(DateUtil.format(directlyStoreQueryDTO.getFormulateDate(), DatePattern.NORM_DATE_PATTERN));
                List<WarehouseReceiveQtyDTO> stockInAndOut = blOlapFacade.getStockInAndOut(stockInAndOutDTO);
                Map<String, WarehouseReceiveQtyDTO> receiveQtyDTOMap = stockInAndOut.stream().collect(Collectors.toMap(WarehouseReceiveQtyDTO::getProductCode, item -> item));
                //实时库存
                QueryRealTimeStockDTO realTimeStockDTO = new QueryRealTimeStockDTO();
                realTimeStockDTO.setBusinessType(RealTimeStockEnum.STORE_CODE.getType());
                realTimeStockDTO.setSkuCodeList(skuList);
                realTimeStockDTO.setCodeList(storeCodeList);
                List<RealTimeStockDTO> stockDTOS = stockCoreFacade.listAvailableQty(realTimeStockDTO);
                Map<String, RealTimeStockDTO> stockDTOMap = stockDTOS.stream().collect(Collectors.toMap(RealTimeStockDTO::getSkuCode, item -> item));
                //实时销量
                DayAvgQueryDTO dayAvgQueryDTO = new DayAvgQueryDTO();
                dayAvgQueryDTO.setChannel(ChannelTypeEnum.DIRECTLY_OPERATE.getCode());
                dayAvgQueryDTO.setStore(directlyStoreQueryDTO.getStoreCode());
                dayAvgQueryDTO.setSkuCodeList(skuList);
                dayAvgQueryDTO.setStartTime(DateUtil.format(directlyStoreQueryDTO.getFormulateDate(), DatePattern.NORM_DATE_PATTERN));
                dayAvgQueryDTO.setEndTime(DateUtil.format(directlyStoreQueryDTO.getFormulateDate(), DatePattern.NORM_DATE_PATTERN));
                List<SkuSaleQtyDTO> salesDayAvg = blOlapFacade.getBoxSalesDayAvg(dayAvgQueryDTO);
                Map<String, SkuSaleQtyDTO> saleDayMap = salesDayAvg.stream().collect(Collectors.toMap(SkuSaleQtyDTO::getProductCode, item -> item));
                storeDTOS.forEach(item -> {
                    //预测浮动 上次系统预测量（单品）—本次系统预测量（单品）
                    BigDecimal forecastFloat = item.getLastForecastQty().subtract(item.getForecastQty());
                    item.setForecastFloat(forecastFloat);
                    //预测浮动比例 上次系统预测量（单品）—本次系统预测量（单品）/本次系统预测量（单品）
                    BigDecimal rate = BigDecimal.ZERO;
                    BigDecimal forecastDifferConfirmRate = BigDecimal.ZERO;
                    //预测确认差异 直营渠道预测量（单品）—直营渠道预测量确认量（单品）
                    BigDecimal forecastDifferConfirm = item.getForecastQty().subtract(item.getConfirmQty());
                    item.setForecastDifferConfirm(forecastDifferConfirm);
                    if (item.getForecastQty().compareTo(BigDecimal.ZERO) == 1) {
                        rate = forecastFloat.divide(item.getForecastQty(), BigDecimal.ROUND_HALF_UP, CommonConstants.FIVE_DECIMAL).multiply(new BigDecimal(100));
                        //预测与确认差异比例 （直营渠道预测量（单品）—直营渠道预测量确认量（单品））/直营渠道预测量（单品）
                        forecastDifferConfirmRate = forecastDifferConfirm.divide(item.getForecastQty(), BigDecimal.ROUND_HALF_UP, CommonConstants.FIVE_DECIMAL).multiply(new BigDecimal(100));
                    }
                    item.setForecastFloatRate(rate + "%");
                    item.setForecastRateConfirm(forecastDifferConfirmRate + "%");
                    //实际收货量
                    item.setActualReceiveQty(ObjectUtil.isEmpty(receiveQtyDTOMap.get(item.getSkuCode()))
                            ? BigDecimal.ZERO : ObjectUtil.isEmpty(receiveQtyDTOMap.get(item.getSkuCode()).
                            getArrivalCount()) ? BigDecimal.ZERO : receiveQtyDTOMap.get(item.getSkuCode()).
                            getArrivalCount());
                    //可用库存
                    item.setActualSaleQty(ObjectUtil.isEmpty(stockDTOMap.get(item.getSkuCode()))
                            ? BigDecimal.ZERO : ObjectUtil.isEmpty(stockDTOMap.get(item.getSkuCode()).
                            getAvailableQty()) ? BigDecimal.ZERO : stockDTOMap.get(item.getSkuCode()).
                            getAvailableQty());
                    //实际销量
                    item.setActualSaleQty(ObjectUtil.isEmpty(saleDayMap.get(item.getSkuCode()))
                            ? BigDecimal.ZERO : ObjectUtil.isEmpty(saleDayMap.get(item.getSkuCode()).
                            getSalesCount()) ? BigDecimal.ZERO : saleDayMap.get(item.getSkuCode()).
                            getSalesCount());
                });
            }
        }
        return storeDTOS;
    }

    /**
     * 如果Pos页面选择了标签，与筛选条件下的sku取交集
     *
     * @param directlyStoreQueryDTO 直接存储查询dto
     * @param list                  列表
     * @return {@link List<String>}
     */
    private List<String> dealTag(DirectlyStoreQueryDTO directlyStoreQueryDTO, List<DirectlyStoreDTO> list) {
        //促销
        List<String> promotionSkuCodes = new ArrayList<>();
        //热销
        List<String> hotSkuCodes = new ArrayList<>();
        //新品
        List<String> newSkuCodes = new ArrayList<>();
        //季节性商品
        List<String> seasonSkuCodes = new ArrayList<>();
        //商品分层的商品
        List<String> layerSkuCodes = new ArrayList<>();
        List<List<String>> listSkuCodes = new ArrayList<>();
        List<String> skuCodeList = list.stream().map(DirectlyStoreDTO::getSkuCode).distinct().collect(Collectors.toList());
        //如果传入的标签不为空
        if (CollectionUtils.isNotEmpty(directlyStoreQueryDTO.getTags()) || StringUtils.isNotBlank(directlyStoreQueryDTO.getLayeredCode())) {
            //如果传入的标签有促销
            if (directlyStoreQueryDTO.getTags().contains(TagEnum.PROMOTION_PRODUCT.getCode())) {
                //先去商品中心查询门店对应的code
                List<ChannelDTO> channelDTOS = baseDataFacade.searchByCodeAndType(null, directlyStoreQueryDTO.getStoreCode(), null,
                        SearchByCodeEnum.STORE.getCode());
                List<String> channelList = channelDTOS.stream().map(ChannelDTO::getChannelCode).distinct().collect(Collectors.toList());
                //根据渠道查询对应的商品
                List<SinglePromotionItemDTO> promotionItemDTOS = promotionCoreFacade.singlePromotion(channelList);
                List<List<String>> lists = promotionItemDTOS.stream().map(SinglePromotionItemDTO::getSkuCodes).collect(Collectors.toList());
                lists.forEach(item -> {
                    promotionSkuCodes.addAll(item);
                });
                listSkuCodes.add(promotionSkuCodes);
            }
            //如果传入的标签有热销
            if (directlyStoreQueryDTO.getTags().contains(TagEnum.HOT_SALE.getCode())) {
                //热销是查询大数据CPI排名前60
                BoxRankQueryDTO boxRankQueryDTO = new BoxRankQueryDTO();
                boxRankQueryDTO.setChannel(ChannelTypeEnum.DIRECTLY_OPERATE.getCode());
                boxRankQueryDTO.setStartTime(DateUtil.format(DateUtil.beginOfWeek(new Date()), DatePattern.NORM_DATE_PATTERN));
                boxRankQueryDTO.setEndTime(DateUtil.format(DateUtil.endOfWeek(new Date()), DatePattern.NORM_DATE_PATTERN));
                boxRankQueryDTO.setSkuCodeList(skuCodeList);
                boxRankQueryDTO.setStore(directlyStoreQueryDTO.getStoreCode());
                List<ProductSaleDTO> salesRank = blOlapFacade.getProductBoxSalesRank(boxRankQueryDTO);
                salesRank.sort((item1, item2) -> Integer.parseInt(item2.getProductCpiRank()) - Integer.parseInt(item1.getProductCpiRank()));
                List<String> skuCode = salesRank.size() > 60 ? salesRank.subList(0, 59).stream().map(ProductSaleDTO::getProductCode).collect(Collectors.toList())
                        : salesRank.stream().map(ProductSaleDTO::getProductCode).collect(Collectors.toList());
                hotSkuCodes.addAll(skuCode);
                listSkuCodes.add(hotSkuCodes);
            }
            //如果传入的标签有新品
            if (directlyStoreQueryDTO.getTags().contains(TagEnum.NEW_PRODUCT.getCode())) {
                List<TagSkuInfoDTO> infoDTOList = itemCoreFacade.getSkuTagGroupBySkuCodes(skuCodeList, TagEnum.TYPE.getCode());
                List<TagSkuInfoDTO> newProduct = infoDTOList.stream().filter(item -> item.getTagCode().equals(TagEnum.NEW_PRODUCT.getCode())).collect(Collectors.toList());
                List<String> newSkuCode = newProduct.stream().map(TagSkuInfoDTO::getSkuCode).distinct().collect(Collectors.toList());
                newSkuCodes.addAll(newSkuCode);
                listSkuCodes.add(newSkuCodes);
            }
            //如果传入的标签有季节性商品
            if (directlyStoreQueryDTO.getTags().contains(TagEnum.SEASON_PRODUCT.getCode())) {
                List<TagSkuInfoDTO> tagGroupBySkuCodes = itemCoreFacade.getSkuTagGroupBySkuCodes(skuCodeList, TagEnum.TYPE.getCode());
                List<TagSkuInfoDTO> skuInfoDTOS = tagGroupBySkuCodes.stream().filter(item -> item.getTagCode().equals(TagEnum.SEASON_PRODUCT.getCode())).collect(Collectors.toList());
                List<String> seasonSku = skuInfoDTOS.stream().map(TagSkuInfoDTO::getSkuCode).distinct().collect(Collectors.toList());
                seasonSkuCodes.addAll(seasonSku);
                listSkuCodes.add(seasonSkuCodes);
            }
            //如果商品分层不为空
            if (StringUtils.isNotBlank(directlyStoreQueryDTO.getLayeredCode())) {
                ProductListQueryDTO productListQueryDTO = new ProductListQueryDTO();
                productListQueryDTO.setChannel(ChannelTypeEnum.DIRECTLY_OPERATE.getCode());
                productListQueryDTO.setStartTime(DateUtil.format(directlyStoreQueryDTO.getFormulateDate(), DatePattern.NORM_DATE_PATTERN));
                productListQueryDTO.setEndTime(DateUtil.format(directlyStoreQueryDTO.getFormulateDate(), DatePattern.NORM_DATE_PATTERN));
                List<String> layerCodes = new ArrayList<>();
                String layerCode = directlyStoreQueryDTO.getLayeredCode();
                layerCodes.add(layerCode);
                productListQueryDTO.setRankType(RandTypeEnum.SALE.getCode());
                productListQueryDTO.setStore(directlyStoreQueryDTO.getStoreCode());
                LayeredSkuCodePageDTO productList = blOlapFacade.getProductList(productListQueryDTO);
                if (ObjectUtil.isNotEmpty(productList)) {
                    List<String> strings = productList.getDataList().stream().map(item -> item.getProductCode()).distinct().collect(Collectors.toList());
                    layerSkuCodes.addAll(strings);
                }
                listSkuCodes.add(layerSkuCodes);
            }
            listSkuCodes.add(skuCodeList);
            return this.retainElementList(listSkuCodes);
        }
        return skuCodeList;
    }

    private List<String> retainElementList(List<List<String>> elementLists) {
        Optional<List<String>> result = elementLists.parallelStream()
                .reduce((a, b) -> {
                    a.retainAll(b);
                    return a;
                });
        return result.orElse(new ArrayList<>());
    }

    @Override
    public Integer updateStatusAndQty(DirectlyStoreQueryDTO directlyStoreQueryDTO, Integer type) {
        //如果传入的是暂存
        if (DirectlyStoreTypeEnum.TEMPORARY_STORAGE.getCode().equals(type)) {
            List<DirectlyStoreQueryDTO> storeQueryDTOS = directlyStoreQueryDTO.getDirectlyStoreQueryDTOS();
            if (CollectionUtils.isEmpty(storeQueryDTOS)) {
                throw new RomeException(ResponseMsg.FAIL_3100.getCode(), ResponseMsg.FAIL_3100.getMsg());
            }
            if (CollectionUtils.isNotEmpty(storeQueryDTOS.stream().filter(item -> ObjectUtil.isEmpty(item.getId())).collect(Collectors.toList()))) {
                throw new RomeException(ResponseMsg.FAIL_3101.getCode(), ResponseMsg.FAIL_3101.getMsg());
            }
            storeQueryDTOS.forEach(item -> {
                item.setStatus(DirectlyStoreStatusEnum.TEMPORARY_STORAGE.getCode());
                item.setSubmitTime(null);
            });
            return directlyStoreRepository.updateStatus(storeQueryDTOS);
        }
        //如果传入的是提交
        if (DirectlyStoreTypeEnum.ALREADY_SUBMIT.getCode().equals(type)) {
            List<DirectlyStoreQueryDTO> storeQueryDTOS = directlyStoreQueryDTO.getDirectlyStoreQueryDTOS();
            if (CollectionUtils.isEmpty(storeQueryDTOS)) {
                throw new RomeException(ResponseMsg.FAIL_3100.getCode(), ResponseMsg.FAIL_3100.getMsg());
            }
            if (CollectionUtils.isNotEmpty(storeQueryDTOS.stream().filter(item -> ObjectUtil.isEmpty(item.getId())).collect(Collectors.toList()))) {
                throw new RomeException(ResponseMsg.FAIL_3101.getCode(), ResponseMsg.FAIL_3101.getMsg());
            }
            storeQueryDTOS.forEach(item -> {
                item.setStatus(DirectlyStoreStatusEnum.ALREADY_SUBMIT.getCode());
                item.setSubmitTime(new Date());
            });
            return directlyStoreRepository.updateStatus(storeQueryDTOS);
        }
        //如果传入的是取消
        if (DirectlyStoreTypeEnum.CANCEL.getCode().equals(type)) {
            //先查询出需要修改的数据
            List<DirectlyStoreDTO> storeDTOS = directlyStoreRepository.listAllInfo(directlyStoreQueryDTO);
            if (CollectionUtils.isEmpty(storeDTOS)) {
                throw new RomeException(ResponseMsg.FAIL_3102.getCode(), ResponseMsg.FAIL_3102.getMsg());
            }
            storeDTOS.forEach(item -> {
                item.setStatus(DirectlyStoreStatusEnum.CANCEL.getCode());
                item.setConfirmQty(item.getForecastQty());
                item.setSubmitTime(null);
            });
            return directlyStoreRepository.updateCancelStatus(storeDTOS);
        }
        throw new RomeException(ResponseMsg.FAIL_3102.getCode(), ResponseMsg.FAIL_3102.getMsg());
    }

    @Override
    public Integer updateStatus() {
        //凌晨一点定时修改加上昨天一共14天的数据
        Date startTime = DateUtil.offsetDay(DateUtil.beginOfDay(new Date()), -1);
        Date endTime = DateUtil.offsetDay(DateUtil.beginOfDay(new Date()), 13);
        List<DirectlyStoreDTO> storeDTOS = directlyStoreRepository.listAllInfoByTime(startTime, endTime);
        if (CollectionUtils.isEmpty(storeDTOS)) {
            throw new RomeException(ResponseMsg.FAIL_3102.getCode(), ResponseMsg.FAIL_3102.getMsg());
        }
        storeDTOS.forEach(item -> {
            item.setUpdateStatus(DirectlyStoreUpdateStatusEnum.N_UPDATE.getCode());
            item.setLastConfirmQty(item.getConfirmQty());
            item.setStatus(DirectlyStoreStatusEnum.ALREADY_SUBMIT.getCode());
        });
        return directlyStoreRepository.updateStatusAndLastConfirmQty(storeDTOS);
    }

    /**
     * 删除当前日期之后的所有数据
     *
     * @param directlyStoreInDOs
     * @return void
     **/
    @Transactional(rollbackFor = Exception.class)
    public void handleBigData(List<DirectlyStoreInDO> directlyStoreInDOs, String storeCode) {
        //删除当前日期之后的所有数据
        directlyStoreRepository.batchDeleteByStartDate(storeCode, dayStartDate);
        if (!CollectionUtils.isEmpty(directlyStoreInDOs)) {
            List<List<DirectlyStoreInDO>> lists = splitTo(directlyStoreInDOs, 5000);
            for (List<DirectlyStoreInDO> list : lists) {
                directlyStoreRepository.batchInsert(list);
            }
        }
    }

    /**
     * 删除当前日期之后的所有数据
     *
     * @param directlyStoreInDOs
     * @return void
     **/
    @Transactional(rollbackFor = Exception.class)
    public void handleRemedialBigData(List<DirectlyStoreInDO> directlyStoreInDOs, String storeCode) {
        //删除当前日期之后的所有数据
        directlyStoreRepository.batchDeleteByStartDate(storeCode, dayStartDate);
        if (!CollectionUtils.isEmpty(directlyStoreInDOs)) {
            List<List<DirectlyStoreInDO>> lists = splitTo(directlyStoreInDOs, 5000);
            for (List<DirectlyStoreInDO> list : lists) {
                directlyStoreRepository.batchInsert(list);
            }
        }
        //删除错误日志信息
        operationLogRecordRepository.deleteBigDataErrorLog(OperationDataEnum.DIRECTLY_SHOP.getTableType(), startTime, endTime, storeCode);
    }

    /**
     * 更新方案处理大数据
     *
     * @param directlyStoreInDOs
     * @param directlyStoreUpDOs
     * @param ids
     * @return void
     **/
    @Transactional(rollbackFor = Exception.class)
    public void handleUpBigData(List<DirectlyStoreInDO> directlyStoreInDOs, List<DirectlyStoreUpDO> directlyStoreUpDOs, List<Long> ids) {
        //先删除
        if (!CollectionUtils.isEmpty(ids)) {
            directlyStoreRepository.rmByIds(ids);
        }
        //更新
        if (!CollectionUtils.isEmpty(directlyStoreUpDOs)) {
            List<List<DirectlyStoreUpDO>> lists = splitTo(directlyStoreUpDOs, 2000);
            for (List<DirectlyStoreUpDO> list : lists) {
                directlyStoreRepository.upByIds(list);
            }
        }
        if (!CollectionUtils.isEmpty(directlyStoreInDOs)) {
            List<List<DirectlyStoreInDO>> lists = splitTo(directlyStoreInDOs, 5000);
            for (List<DirectlyStoreInDO> list : lists) {
                directlyStoreRepository.batchInsert(list);
            }
        }
    }

    @Override
    public void delete(String opSign) {
        directlyStoreRepository.delete(opSign);
    }

    @Override
    public List<DirectlyStoreDTO> listByCondition(DirectlyStoreDTO directlyStore) {
        List<DirectlyStoreDTO> storeInfo = directlyStoreRepository.listByCondition(directlyStore);
        List<String> skuCodeList = storeInfo.stream().filter(e -> e.getSkuCode() != null)
                .map(DirectlyStoreDTO::getSkuCode).collect(Collectors.toList());
        if (CollectionUtils.isNotEmpty(skuCodeList)) {
            List<UnitRateQueryDTO> queryList = new ArrayList<>();
            Long baseUnit = SkuUnitTypeEnum.BASIS_UNIT.getUnitType();
            Long unitType = directlyStore.getUnitType();
            if (!baseUnit.equals(unitType)) {
                for (String sku : skuCodeList) {
                    UnitRateQueryDTO unit = new UnitRateQueryDTO();
                    unit.setSkuCode(sku);
                    unit.setFromUnitType(baseUnit);
                    unit.setToUnitType(unitType);
                    queryList.add(unit);
                }
                Map<String, SkuUnitDTO> unitInfo = redisCacheService.getUnitConversionRatio(queryList);
                for (DirectlyStoreDTO val : storeInfo) {
                    SkuUnitDTO skuUnit = unitInfo.get(val.getSkuCode() + baseUnit + unitType);
                    if (ObjectUtil.isEmpty(skuUnit)){
                        continue;
                    }
                    BigDecimal scale = BigDecimal.valueOf(skuUnit.getScale());
                    val.setConfirmQty(val.getConfirmQty().multiply(scale));
                }
            }
            return storeInfo;
        }
        return storeInfo;
    }
}
